unit FrmConfig;

interface

uses
  Classes, SysUtils, IniFiles, Forms, Windows;

const
  csIniGeneralSection = 'General';
  csIniColumnSection = 'Column';
  csIniFinderSection = 'Finder';

  {Section: General}
  csIniGeneralWindowMaxed = 'WindowMaxed';
  csIniGeneralWindowLeft = 'WindowLeft';
  csIniGeneralWindowTop = 'WindowTop';
  csIniGeneralWindowWidth = 'WindowWidth';
  csIniGeneralWindowHeigh = 'WindowHeigh';
  csIniGeneralTemplateWidth = 'TemplateWidth';
  csIniGeneralSectionWidht = 'SectionWidht';
  csIniGeneralMainHeight = 'MainHeight';
  csIniGeneralShellPath = 'ShellPath';
  csIniGeneralRemoteServer = 'RemoteServer';

  {Section: Column}
  csIniColumnLvwCmdCol0 = 'LvwCmdCol0';
  csIniColumnLvwCmdCol1 = 'LvwCmdCol1';
  csIniColumnLvwCmdCol2 = 'LvwCmdCol2';
  csIniColumnLvwCmdCol3 = 'LvwCmdCol3';
  csIniColumnLvwCmdCol4 = 'LvwCmdCol4';
  csIniColumnLvwCmdCol5 = 'LvwCmdCol5';
  csIniColumnLvwCmdCol6 = 'LvwCmdCol6';
  csIniColumnLvwSvcCol0 = 'LvwSvcCol0';
  csIniColumnLvwCronCol0 = 'LvwCronCol0';
  csIniColumnLvwCronCol1 = 'LvwCronCol1';
  csIniColumnLvwCronCol2 = 'LvwCronCol2';
  csIniColumnLvwCronCol3 = 'LvwCronCol3';
  csIniColumnLvwCronCol4 = 'LvwCronCol4';
  csIniColumnLvwCronCol5 = 'LvwCronCol5';
  csIniColumnLvwDBCol0 = 'LvwDBCol0';
  csIniColumnLvwDBCol1 = 'LvwDBCol1';
  csIniColumnLvwDBCol2 = 'LvwDBCol2';
  csIniColumnLvwDBCol3 = 'LvwDBCol3';
  csIniColumnLvwDBCol4 = 'LvwDBCol4';

  {Section: Finder}
  csIniFinderWindowLeft = 'WindowLeft';
  csIniFinderWindowTop = 'WindowTop';
  csIniFinderWindowWidth = 'WindowWidth';
  csIniFinderWindowHeight = 'WindowHeight';

type
  TIniOptions = class(TObject)
  private
    {Section: General}
    FGeneralWindowMaxed: Boolean;
    FGeneralWindowLeft: Integer;
    FGeneralWindowTop: Integer;
    FGeneralWindowWidth: Integer;
    FGeneralWindowHeigh: Integer;
    FGeneralTemplateWidth: Integer;
    FGeneralSectionWidht: Integer;
    FGeneralMainHeight: Integer;
    FGeneralShellPath: string;
    FGeneralRemoteServer: string;

    {Section: Column}
    FColumnLvwCmdCol0: Integer;
    FColumnLvwCmdCol1: Integer;
    FColumnLvwCmdCol2: Integer;
    FColumnLvwCmdCol3: Integer;
    FColumnLvwCmdCol4: Integer;
    FColumnLvwCmdCol5: Integer;
    FColumnLvwCmdCol6: Integer;
    FColumnLvwSvcCol0: Integer;
    FColumnLvwCronCol0: Integer;
    FColumnLvwCronCol1: Integer;
    FColumnLvwCronCol2: Integer;
    FColumnLvwCronCol3: Integer;
    FColumnLvwCronCol4: Integer;
    FColumnLvwCronCol5: Integer;
    FColumnLvwDBCol0: Integer;
    FColumnLvwDBCol1: Integer;
    FColumnLvwDBCol2: Integer;
    FColumnLvwDBCol3: Integer;
    FColumnLvwDBCol4: Integer;

    {Section: Finder}
    FFinderWindowLeft: Integer;
    FFinderWindowTop: Integer;
    FFinderWindowWidth: Integer;
    FFinderWindowHeight: Integer;
  public
    procedure LoadSettings(Ini: TIniFile);
    procedure SaveSettings(Ini: TIniFile);
    
    procedure LoadFromFile(const FileName: string);
    procedure SaveToFile(const FileName: string);

    {Section: General}
    property GeneralWindowMaxed: Boolean read FGeneralWindowMaxed write FGeneralWindowMaxed;
    property GeneralWindowLeft: Integer read FGeneralWindowLeft write FGeneralWindowLeft;
    property GeneralWindowTop: Integer read FGeneralWindowTop write FGeneralWindowTop;
    property GeneralWindowWidth: Integer read FGeneralWindowWidth write FGeneralWindowWidth;
    property GeneralWindowHeigh: Integer read FGeneralWindowHeigh write FGeneralWindowHeigh;
    property GeneralTemplateWidth: Integer read FGeneralTemplateWidth write FGeneralTemplateWidth;
    property GeneralSectionWidht: Integer read FGeneralSectionWidht write FGeneralSectionWidht;
    property GeneralMainHeight: Integer read FGeneralMainHeight write FGeneralMainHeight;
    property GeneralShellPath: string read FGeneralShellPath write FGeneralShellPath;
    property GeneralRemoteServer: string read FGeneralRemoteServer write FGeneralRemoteServer;

    {Section: Column}
    property ColumnLvwCmdCol0: Integer read FColumnLvwCmdCol0 write FColumnLvwCmdCol0;
    property ColumnLvwCmdCol1: Integer read FColumnLvwCmdCol1 write FColumnLvwCmdCol1;
    property ColumnLvwCmdCol2: Integer read FColumnLvwCmdCol2 write FColumnLvwCmdCol2;
    property ColumnLvwCmdCol3: Integer read FColumnLvwCmdCol3 write FColumnLvwCmdCol3;
    property ColumnLvwCmdCol4: Integer read FColumnLvwCmdCol4 write FColumnLvwCmdCol4;
    property ColumnLvwCmdCol5: Integer read FColumnLvwCmdCol5 write FColumnLvwCmdCol5;
    property ColumnLvwCmdCol6: Integer read FColumnLvwCmdCol6 write FColumnLvwCmdCol6;
    property ColumnLvwSvcCol0: Integer read FColumnLvwSvcCol0 write FColumnLvwSvcCol0;
    property ColumnLvwCronCol0: Integer read FColumnLvwCronCol0 write FColumnLvwCronCol0;
    property ColumnLvwCronCol1: Integer read FColumnLvwCronCol1 write FColumnLvwCronCol1;
    property ColumnLvwCronCol2: Integer read FColumnLvwCronCol2 write FColumnLvwCronCol2;
    property ColumnLvwCronCol3: Integer read FColumnLvwCronCol3 write FColumnLvwCronCol3;
    property ColumnLvwCronCol4: Integer read FColumnLvwCronCol4 write FColumnLvwCronCol4;
    property ColumnLvwCronCol5: Integer read FColumnLvwCronCol5 write FColumnLvwCronCol5;
    property ColumnLvwDBCol0: Integer read FColumnLvwDBCol0 write FColumnLvwDBCol0;
    property ColumnLvwDBCol1: Integer read FColumnLvwDBCol1 write FColumnLvwDBCol1;
    property ColumnLvwDBCol2: Integer read FColumnLvwDBCol2 write FColumnLvwDBCol2;
    property ColumnLvwDBCol3: Integer read FColumnLvwDBCol3 write FColumnLvwDBCol3;
    property ColumnLvwDBCol4: Integer read FColumnLvwDBCol4 write FColumnLvwDBCol4;

    {Section: Finder}
    property FinderWindowLeft: Integer read FFinderWindowLeft write FFinderWindowLeft;
    property FinderWindowTop: Integer read FFinderWindowTop write FFinderWindowTop;
    property FinderWindowWidth: Integer read FFinderWindowWidth write FFinderWindowWidth;
    property FinderWindowHeight: Integer read FFinderWindowHeight write FFinderWindowHeight;
  end;

var
  IniOptions: TIniOptions = nil;

implementation

procedure TIniOptions.LoadSettings(Ini: TIniFile);
begin
  if Ini <> nil then
  begin
    {Section: General}
    FGeneralWindowMaxed := Ini.ReadBool(csIniGeneralSection, csIniGeneralWindowMaxed, False);
    FGeneralWindowLeft := Ini.ReadInteger(csIniGeneralSection, csIniGeneralWindowLeft, 139);
    FGeneralWindowTop := Ini.ReadInteger(csIniGeneralSection, csIniGeneralWindowTop, 102);
    FGeneralWindowWidth := Ini.ReadInteger(csIniGeneralSection, csIniGeneralWindowWidth, 1704);
    FGeneralWindowHeigh := Ini.ReadInteger(csIniGeneralSection, csIniGeneralWindowHeigh, 912);
    FGeneralTemplateWidth := Ini.ReadInteger(csIniGeneralSection, csIniGeneralTemplateWidth, 487);
    FGeneralSectionWidht := Ini.ReadInteger(csIniGeneralSection, csIniGeneralSectionWidht, 175);
    FGeneralMainHeight := Ini.ReadInteger(csIniGeneralSection, csIniGeneralMainHeight, 416);
    FGeneralShellPath := Ini.ReadString(csIniGeneralSection, csIniGeneralShellPath, 'D:\My Projects\SpecGen\sc.sh');
    FGeneralRemoteServer := Ini.ReadString(csIniGeneralSection, csIniGeneralRemoteServer, 'http://172.23.1.226/cgi-bin/specscript/');

    {Section: Column}
    FColumnLvwCmdCol0 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol0, 175);
    FColumnLvwCmdCol1 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol1, 100);
    FColumnLvwCmdCol2 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol2, 120);
    FColumnLvwCmdCol3 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol3, 120);
    FColumnLvwCmdCol4 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol4, 75);
    FColumnLvwCmdCol5 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol5, 118);
    FColumnLvwCmdCol6 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCmdCol6, 80);
    FColumnLvwSvcCol0 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwSvcCol0, 1046);
    FColumnLvwCronCol0 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol0, 180);
    FColumnLvwCronCol1 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol1, 60);
    FColumnLvwCronCol2 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol2, 387);
    FColumnLvwCronCol3 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol3, 100);
    FColumnLvwCronCol4 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol4, 249);
    FColumnLvwCronCol5 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwCronCol5, 162);
    FColumnLvwDBCol0 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwDBCol0, 120);
    FColumnLvwDBCol1 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwDBCol1, 120);
    FColumnLvwDBCol2 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwDBCol2, 50);
    FColumnLvwDBCol3 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwDBCol3, 120);
    FColumnLvwDBCol4 := Ini.ReadInteger(csIniColumnSection, csIniColumnLvwDBCol4, 120);

    {Section: Finder}
    FFinderWindowLeft := Ini.ReadInteger(csIniFinderSection, csIniFinderWindowLeft, 120);
    FFinderWindowTop := Ini.ReadInteger(csIniFinderSection, csIniFinderWindowTop, 120);
    FFinderWindowWidth := Ini.ReadInteger(csIniFinderSection, csIniFinderWindowWidth, 640);
    FFinderWindowHeight := Ini.ReadInteger(csIniFinderSection, csIniFinderWindowHeight, 480);
  end;
end;

procedure TIniOptions.SaveSettings(Ini: TIniFile);
begin
  if Ini <> nil then
  begin
    {Section: General}
    Ini.WriteBool(csIniGeneralSection, csIniGeneralWindowMaxed, FGeneralWindowMaxed);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralWindowLeft, FGeneralWindowLeft);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralWindowTop, FGeneralWindowTop);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralWindowWidth, FGeneralWindowWidth);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralWindowHeigh, FGeneralWindowHeigh);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralTemplateWidth, FGeneralTemplateWidth);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralSectionWidht, FGeneralSectionWidht);
    Ini.WriteInteger(csIniGeneralSection, csIniGeneralMainHeight, FGeneralMainHeight);
    Ini.WriteString(csIniGeneralSection, csIniGeneralShellPath, FGeneralShellPath);
    Ini.WriteString(csIniGeneralSection, csIniGeneralRemoteServer, FGeneralRemoteServer);

    {Section: Column}
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol0, FColumnLvwCmdCol0);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol1, FColumnLvwCmdCol1);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol2, FColumnLvwCmdCol2);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol3, FColumnLvwCmdCol3);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol4, FColumnLvwCmdCol4);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol5, FColumnLvwCmdCol5);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCmdCol6, FColumnLvwCmdCol6);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwSvcCol0, FColumnLvwSvcCol0);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol0, FColumnLvwCronCol0);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol1, FColumnLvwCronCol1);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol2, FColumnLvwCronCol2);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol3, FColumnLvwCronCol3);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol4, FColumnLvwCronCol4);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwCronCol5, FColumnLvwCronCol5);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwDBCol0, FColumnLvwDBCol0);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwDBCol1, FColumnLvwDBCol1);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwDBCol2, FColumnLvwDBCol2);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwDBCol3, FColumnLvwDBCol3);
    Ini.WriteInteger(csIniColumnSection, csIniColumnLvwDBCol4, FColumnLvwDBCol4);

    {Section: Finder}
    Ini.WriteInteger(csIniFinderSection, csIniFinderWindowLeft, FFinderWindowLeft);
    Ini.WriteInteger(csIniFinderSection, csIniFinderWindowTop, FFinderWindowTop);
    Ini.WriteInteger(csIniFinderSection, csIniFinderWindowWidth, FFinderWindowWidth);
    Ini.WriteInteger(csIniFinderSection, csIniFinderWindowHeight, FFinderWindowHeight);
  end;
end;

procedure TIniOptions.LoadFromFile(const FileName: string);
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create(FileName);
  try
    LoadSettings(Ini);
  finally
    Ini.Free;
  end;
end;

procedure TIniOptions.SaveToFile(const FileName: string);
var
  Ini: TIniFile;
begin
  Ini := TIniFile.Create(FileName);
  try
    SaveSettings(Ini);
  finally
    Ini.Free;
  end;
end;

initialization
  IniOptions := TIniOptions.Create;

finalization
  IniOptions.Free;

end.

